using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;

public class Shoot : NetworkBehaviour
{
    [SerializeField]private GameObject bulletPrefab;
    [SerializeField]private NetworkObject bullets;

    private void Awake()
    {
        bullets = GameObject.Find("bullets").GetComponent<NetworkObject>();
    }

    void Update()
    {
        if (IsOwner && Input.GetKeyDown(KeyCode.Space))
        {
            FireServerRpc();
        }
    }

    [ServerRpc]
    private void FireServerRpc()
    {
        GameObject go = Instantiate(bulletPrefab, bullets.transform);
        go.transform.position = transform.position + Vector3.up;
        go.transform.eulerAngles = Vector3.zero;
        go.transform.localScale = Vector3.one * 0.1f;
        go.GetComponent<bullet>().InitDriection(transform.forward);
        go.GetComponent<NetworkObject>().Spawn();
        go.GetComponent<NetworkObject>().TrySetParent(bullets.transform);
    }
}
